package com.koala.javacpptemplate;

import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

public class MainActivity extends AppCompatActivity {

    // 声明本地方法
    public native int sum(int a, int b);

    // 加载本地库
    static {
        System.loadLibrary("javacpptemplate"); // 这里一定要确保一致性，最好直接使用文件名
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_main);
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });

        int a = 5, b = 7;
        // 调用本地方法求和
        int result = sum(a, b);

        // 显示结果
        Toast.makeText(this, "Sum: " + result, Toast.LENGTH_LONG).show();

        // 打印日志
        Log.i("Sum Test", "Sum: " + result);
    }
}